var $ = getApp(), methods = require("../methods.js");
var interval = null;
Page(Object.assign({}, methods, {
	data: {
		prodata: '',
		isload: 0,
		djs:'',
	},
	_onLoad: function (option) {
		var that = this;
		$.get('order/detail', { id: that.options.id }, function (res) {
			that.setData({
				iscommentdp:res.iscommentdp,
				detail: res.detail,
				prolist: res.prolist,
				shopset: res.shopset,
				storeinfo: res.storeinfo,
				lefttime:res.lefttime,
				codtxt:res.codtxt,
				isload: 1
			});
			$.loading(false);
			if(res.lefttime > 0){
				interval = setInterval(function(){
					that.setData({lefttime: that.data.lefttime+1})
					that.getdjs();
				},1000)
			}
		});

	},
	getdjs:function(){
		var that = this
		var totalsec = that.data.lefttime;
		if(totalsec <=0){
			that.setData({djs:'00时00分00秒'})
		}else{
			var houer = Math.floor(totalsec/3600);
			var min = Math.floor((totalsec - houer *3600)/60);
			var sec = totalsec - houer*3600 - min*60
			var djs = (houer<10?'0':'')+houer+'时'+(min<10?'0':'')+min+'分'+(sec<10?'0':'')+sec+'秒';
			that.setData({djs:djs})
		}
	},
	todel: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要删除该订单吗?', function () {
			$.post('order/delOrder', { orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					$.goback(true);
				}, 1000)
			}, '删除中');
		})
	},
	toclose: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要关闭该订单吗?', function () {
			$.post('order/closeOrder', { orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					that.onLoad();
				}, 1000)
			}, '提交中');
		})
	},
	orderCollect: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要收货吗?', function () {
			$.post('order/orderCollect', { orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					that.onLoad();
				}, 1000)
			})
		}, '收货中');
	},
	choosePstime:function(e){
		var that = this;
		that.setData({pstimeDialogShow:true,pstimeIndex:-1})
	},
	pstimeRadioChange:function(e){
		this.setData({pstimeIndex:e.detail.value})
	},
	pstimeSelectConfirm:function(){
		var that = this;
		var detail = that.data.detail
		var pstimeIndex = that.data.pstimeIndex
		var express_data = detail.expressItems[pstimeIndex];
		that.setData({pstimeDialogShow:false})
		$.goto('logistics?express='+express_data.express_com+'&express_no='+express_data.express_no);
	},
	hidePstimeDialog:function(){
		this.setData({pstimeDialogShow:false})
	},
	onUnload:function(){
		clearInterval(interval);
	}
}))